
import { _decorator, Component, Node } from 'cc';
import { ShopViews } from './ShopViews';
const { ccclass, property } = _decorator;

@ccclass('BtnTypesCmp')
export class BtnTypesCmp extends Component {
    @property(ShopViews)
    shopViews: ShopViews = null;

    _curType = 0;
    _checkNodes: { [type: number]: Node } = {};

    onLoad() {
        //类型 默认从1开始
        for (let i = 0; i < this.node.children.length; i++) {
            const e = this.node.children[i];
            let checkNode = e.getChildByName('check');
            this._checkNodes[i + 1] = checkNode;
        }
    }

    start() {
        this.changeTypes(1);
    }

    //切换展示类型
    changeTypes(t: number) {
        if (this._curType == t) return;
        this._curType = t;
        //切换按钮状态
        for (const key in this._checkNodes) {
            this._checkNodes[key].active = (+key) == t;
        }
        //切换展示内容
        this.shopViews.changView(this._curType);
    }



    //--------------------Btns------------------
    //类型1
    onType1Click() {
        this.changeTypes(1);
    }
    //类型2
    onType2Click() {
        this.changeTypes(2);
    }
    //类型3
    onType3Click() {
        this.changeTypes(3);
    }
}
